package com.yc.cloud.admin.controller;

import com.yc.cloud.admin.service.OrderService;
import com.yc.cloud.admin.vo.OrderVo;
import com.yc.cloud.common.basic.api.ResponseResult;
import com.yc.cloud.common.basic.dto.BasePageReqDTO;
import com.yc.cloud.common.orm.CommonPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import jakarta.annotation.Resource;
import lombok.val;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * 订单
 *
 * @author Yancy
 * @date 2024-01-03
 */
@RestController
@RequestMapping("/orders")
@Api(value = "订单", tags = "订单接口")
public class OrderController {

    @Resource
    private OrderService orderService;


    @GetMapping
    @ApiOperation(value = "订单列表", notes = "支持分页查询,字段模糊匹配,排序等")
    public ResponseResult<CommonPage<OrderVo>> list(BasePageReqDTO param) {
        val result = orderService.list(param);
        return ResponseResult.success(CommonPage.restPage(result));
    }


    @GetMapping("{id}")
    @ApiOperation(value = "订单详情", notes = "根据ID查询")
    public ResponseResult<OrderVo> get(@PathVariable @ApiParam(value = "ID", required = true) Long id) {
        val order = orderService.getById(id);
        val result = orderService.convertVo(order);
        return ResponseResult.success(result);
    }


//    @PostMapping
//    @ApiOperation(value = "添加订单", notes = "添加")
//    public ResponseResult<Order> create(@Validated @RequestBody Order order) {
//        val result = orderService.save(order);
//        return result ? ResponseResult.success(order) : ResponseResult.failed();
//    }
//
//
//    @ApiOperation(value = "删除订单", notes = "通过ID删除")
//    @DeleteMapping(value = "{id}")
//    public ResponseResult<Long> delete(@PathVariable @ApiParam(value = "ID", required = true) Long id) {
//        val result = orderService.removeById(id);
//        return result ? ResponseResult.success() : ResponseResult.failed();
//    }
//
//
//    @ApiOperation(value = "修改订单", notes = "通过ID修改")
//    @PutMapping(value = "{id}")
//    public ResponseResult<Long> update(@PathVariable @ApiParam(value = "ID", required = true) Long id, @Validated @RequestBody Order order) {
//        order.setId(id);
//        val result = orderService.updateById(order);
//        return result ? ResponseResult.success() : ResponseResult.failed();
//    }
}
